<template>
  <div class="">
    <div class="home-top-wrapper">
      <ul>
        <li @click="toTiLaMiSu()">
          <img src="http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f10_n4na.png" alt="">
        </li>
        <li @click="toMaKaLong()">
          <img src="http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f50_iiwi.png" alt="">
        </li>
        <li @click="toZhiSHi">
          <img src="http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f30_j45g.png" alt="">
        </li>
        <li @click="toBuDing">
          <img src="http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f20_1uu6.png" alt="">
        </li>
        <li @click="toXishi">
          <img src="http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f40_ye71.png" alt="">
        </li>
      </ul>
    </div>
    <div class="img-wrapper"></div>
    <div class="sweet-info">
      <div class="left-img-wrapper">
        <div class="circle-img"></div>
      </div>
      <div class="sweets-wrapper">
        <ul>
          <li v-for="item in productInfo" :key="item.id">
            <router-link tag="div" :to="'/detail/' + item.productId" class="img-wrapper-product">
              <img :src="item.productImage" alt="" width="100%">
            </router-link>
            <p class="title">{{item.productName}}</p>
            <p class="classify">{{item.classifyName}}</p>
            <p class="bazaar-price">市场价: {{item.bazaarPrice}}</p>
            <p class="price">价格: {{item.salePrice}}</p>
            <span class="cart" @click="addCart(item.productId)">加入购物车</span>
          </li>
        </ul>
      </div>
      <modal :showModal="showModal" @close="closeModal">
        <span class="LoginMessage">{{this.loginFlag}},请先登录</span>
      </modal>
      <modal :showModal="showModalCart" @close="closeModal">
        <span class="LoginMessage">加入购物车成功</span>
        <span @click="showModalCart = false" class="continue">继续购物</span>
        <router-link tag="span" to='/' class="checkcart">查看购物车</router-link>
      </modal>
    </div>
    <div class="yellow-img-wrapper"></div>
    <recommend></recommend>
  </div>
</template>

<script>
import recommend from '../components/recommend'
import axios from 'axios'
import modal from '../components/modal'
export default {
  data () {
    return {
      productInfo: [],
      clickModal: false,
      showModal: false,
      loginFlag: '',
      showModalCart: false
    }
  },
  components: {
    recommend,
    modal
  },
  methods: {
    addCart (productId) {
      axios.post('/goods/addCart', {
        productId: productId
      }).then((response) => {
        console.log(response)
        if (response.data.status === 0) {
          this.showModalCart = true
        } else {
          this.showModal = true
          this.loginFlag = response.data.msg
        }
      })
    },
    closeModal () {
      this.showModal = false
      this.showModalCart = false
    },
    getHomeInfo () {
      axios.get('/goods/list').then((response) => {
        let res = response.data
        if (res.status === 0) {
          this.productInfo = res.result.list.slice(0, 8)
        } else {
          this.productInfo = []
        }
      })
    },
    toTiLaMiSu () {
      this.$router.push({path: '/sweets',
        query: {classtify: 'T'}
      })
    },
    toMaKaLong () {
      this.$router.push({path: '/sweets',
        query: {classtify: 'M'}
      })
    },
    toZhiSHi () {
      this.$router.push({path: '/sweets',
        query: {classtify: 'Z'}
      })
    },
    toBuDing () {
      this.$router.push({path: '/sweets',
        query: {classtify: 'B'}
      })
    },
    toXishi () {
      this.$router.push({path: '/sweets',
        query: {classtify: 'X'}
      })
    }
  },
  mounted () {
    this.getHomeInfo()
  }
}
</script>

<style lang="scss" scoped>
@import '../assets/scss/triangle.scss';
.home-top-wrapper {
  height: 300px;
  width: 100%;
  background-color: #80d47c;
  margin-top: -2px;
  position: relative;
  ul {
    display: flex;
    width: 80%;
    margin: 0 auto;
    padding-top: 60px;
    li {
      width: 300px;
      height: 200px;
      // background-color: red;
      display: inline-block;
      justify-content: space-around;
      align-items: center;
      cursor:pointer;
    }
  }
}
.img-wrapper {
  @include triangle("http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f04_rvd7.png")
}
.sweet-info {
  height: 699px;
  background-color: #f8f5bc;
  position: relative;
  .left-img-wrapper {
    width: 20px;
    background-color: #fff;
    padding-left: 10px;
    padding-right: 10px;
    padding-top: 25px;
    position: absolute;
    top: 90px;
    left: 170px;
    .circle-img {
      padding: 0px;
      border: 0px solid transparent;
      height: 553px;
      width: 48px;
      display: block;
      background-image: url(http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f03_8g62.png);
      background-repeat: repeat-y;
    }
  }
  .sweets-wrapper {
    width: 1018px;
    background-color: #fff;
    height: 578px;
    position: absolute;
    left: 210px;
    top: 90px;
    ul {
      padding: 25px;
      padding-top: 25px;
      li {
        width: 230px;
        height: 254px;
        display: inline-block;
        // background-color: red;
        border: 1px solid #ccc;
        margin-right: 10px;
        margin-bottom: 10px;
        line-height: 15px;
        cursor: pointer;
        .img-wrapper-product {
          width: 210px;
          height: 170px;
          overflow: hidden;
          margin: 10px;
          margin-bottom: 0px;
        }
        .title {
          font-size: 12px;
          color:#8f6228;
          font-weight: bold !important;
          margin-left: 15px;
        }
        .classify {
          font-size: 12px;
          color: #ffd676;
          margin-left: 15px;
          cursor: pointer;
        }
        .classify:hover {
          color: #2c90ff;
        }
        .bazaar-price {
          font-size: 12px;
          color: #bfa27b;
          margin-left: 15px;
          text-decoration:line-through;
        }
        .price {
          font-size: 12px;
          color: #ff3c00;
          margin-left: 15px;
        }
        .cart {
          padding: 5px;
          background-color: #ffd676;
          font-size: 8px;
          float: right;
          margin-right: 5px;
          margin-top: -10px;
          border-radius: 8px;
          color: #fff;
        }
      }
      li:hover {
        border: 1px solid #ffd676;
      }
    }
  }
  .LoginMessage {
    color: #fff;
    position: absolute;
    left: 155px;
    top: 134px;
    font-size: 20px;
  }
  .continue {
    position: absolute;
    bottom: 79px;
    padding: 11px;
    border: 1px solid #fff;
    color: #fff;
    left: 110px;
    cursor: pointer;
  }
  .checkcart {
    position: absolute;
    bottom: 80px;
    padding: 10px;
    color: #fff;
    border: 1px solid #fff;
    left: 240px;
    cursor: pointer;
  }
}
.yellow-img-wrapper {
  @include triangle("http://tpl-c913457.pic-tpl.websiteonline.cn/upload/f05_hiiv.png")
}
</style>
